package PTA_JAVA.JavaA.Javademo11;
import java.util.ArrayList;
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        ArrayList<String> strList = new ArrayList<String>();
        Scanner sc = new Scanner(System.in);
        String a=sc.next();
        while (!a.equals("!!end!!")){
            strList.add(a);
            a = sc.next();
        }
        strList.add(0,"begin");
        strList.add("end");
        System.out.println(strList);

        String str=sc.next();
        int f=-1;
        for(int i=0;i< strList.size();i++){
            if(strList.get(i).equals(str)){
                f=i;
                break;
            }
        }
        System.out.println(strList.contains(str));
        System.out.println(f);
        f=-1;
        for(int i=strList.size()-1;i>=0;i--){
            if(strList.get(i).equals(str)){
                f=i;
                break;
            }
        }
        System.out.println(f);
        System.out.println(strList.remove(0));
        System.out.println(strList);

        str = sc.next();
        strList.set(1,str);
        System.out.println(strList);

        str = sc.next();
        ArrayList<String> strList1 = new ArrayList<String>();
        for(String i:strList){
            if(i.contains(str)){
                strList1.add(i);
            }
        }
        System.out.println(strList1);


        for (String i:strList){
            if (str.equals(i)){
                strList.remove(i);
                break;
            }
        }
        System.out.println(strList);


        strList.clear();
        System.out.println(strList+","+strList.size()+","+ strList.isEmpty());
    }
}

